import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  //动态修改网页标题
  document.title = to.meta && to.meta.title || '饿了么';
var token = localStorage.getItem('token');

//判断是否是跳转到 订单页 或 我的页
if( to.path == '/index/moue' || to.path == '/index/mine' ){
  if( token ){ //已登录, 放行
    next();
  }else{ //未登录, 跳转到登录页
    next('/login');
    // router.push('/login');
  }
}else{ //跳转到其他页面
  next();
}
})
export default router
